package ttt;
import player.*;
import java.util.*;
import gui.*;

public class Main {
	
	public static void main(String[] args) {
		System.out.println("Get ready to play TicTacToe");
		System.out.println();
		System.out.println("Player one");
		Player p1 = answer();
		System.out.println();
		System.out.println("Player two");
		Player p2 = answer();
		boolean again = true;

		do {
			System.out.println();
			BoardUserInterface gui = new GraphicalBoard();
			TicTacToe t = new TicTacToe(p1, p2, gui);
			gui.setTicTacToeBoard(t);
			System.out.println("Player one (" + p1 + ") plays as " + t.intToChar(t.getPlayerMark(p1)));
			System.out.println("Player two (" + p2 + ") plays as " + t.intToChar(t.getPlayerMark(p2)));
			System.out.println();
			t.play();
			
			Scanner scanner = new Scanner(System.in);
			System.out.print("Do you want to play again with the same settings? (y/n): ");
			String ans = scanner.next();
			if(ans.equals("n"))
				again = false;
		} while(again);
	}
	
	private static Player answer() {
		Scanner scanner = new Scanner(System.in);
		String[] c = {"Easy comp", "Expert comp", "Human"};
		for(int i = 0; i < c.length; i++)
			System.out.println(i + " - " + c[i]);
		
		System.out.print("Enter a number (0-" + (c.length - 1) + "): ");
		int j = scanner.nextInt();
		switch(j) {
		case 0:
			return new IdiotAI();
		case 1:
			return new ExpertAI();
		case 2:
			return new HumanPlayer();
		default:
			System.out.println();
			System.out.println("Try again");
			return answer();
		}
	}
}